function ConferenceCtrl(){}
import { DispatchCtrlLib } from '../chromeLib/DispatchCtrlLib'
import { DispatchVideoLib } from '../chromeLib/DispatchVideoLib'

let VideoLibConferenceArray = new Array();
let VideoLibConferenceLocalArray = new Array();
let testarray = [111,222,333,444];
/**
 * 当前会议信息
 * @param   confId        会议室ID   string
 * @param   type          会议类型
 * @param   pwd          会议密码   string
 */
ConferenceCtrl.CurrentConferenceInfo=function(){
  let roomInfo = DispatchCtrlLib.CurrentConferenceInfo();
  if(roomInfo){
    return roomInfo;
  }
},

/**
 * 发起会议    //实际上就是makeaudiocall和makevideocall
 * @param   confId        会议室ID   string
 * @param   type          会议类型
 * @param   pwd          会议密码   string
 */

ConferenceCtrl.MakeConference=function(confId,type,pwd){
    let ret;
    if(type ==1){    //视频会议
        ret=DispatchCtrlLib.ConferenceEnter(confId,type,pwd);
        if(ret<0){
          console.log("参数错误");
          return;
        }
    }else{
        ret=DispatchCtrlLib.ConferenceEnter(confId,type,pwd);
        if(ret==-3){
          console.log("参数错误");
          return;
        }
    }
    let Msg = "MakeConference";
    let Parm = new Object();
    Parm.type = type;
    Parm.channelId = ret;
    Parm.conferenceId =confId;
    return ret;
  }

/**
 * 获取最后一条会议邀请信息
 */
ConferenceCtrl.VoipLastIncomingCall=function() {
    DispatchCtrlLib.VoipLastIncomingCall();
 }
/**
 * 邀请会议成员
 * @param   confId        会议室ID   string
 * @param   ExtNumList     邀请的成员
 */

ConferenceCtrl.ConferenceInvite=function(ExtNumList,confId) {
  let ret = DispatchCtrlLib.ConferenceInvite(ExtNumList,confId);
  if (ret < 0) {
    console.log("参数错误");
  } else {
    let Msg = "ConferenceInvite";
    let Parm = new Object();
    Parm.ret = ret;
    Parm.ExtNumList = ExtNumList;
  }
  return ret;
}

/**
 * 设置会议音量
 * @param   CallID,        会议室ID   int
 * @param   Volume      音量   0-100   int
 */

ConferenceCtrl.ConferenceSetvoice=function(Volume) {
  let ret = DispatchCtrlLib.ConferenceSetVolume(Volume);
  return ret
}

/**
 * 设置本地mic开关     实际 就是IP通话禁麦
 * @param   CallID,        会议室ID   int
 * @param   Mute      0-讲话 1-禁麦    int
 */

ConferenceCtrl.ConferenceSetMicButton=function(Mute) {
  let ret = DispatchCtrlLib.ConferenceLocalMicMute(Mute);
  return ret;
}

/**
 * 设置本地扬声器开关  实际就是设置IP通话音量
 * @param   CallID,        会议室ID   int
 * @param   Volume      音量   0-100   int
 */
//TODO
ConferenceCtrl.ConferenceSetVoiceButton=function(CallID,Volume) {
  let ret = DispatchCtrlLib.ConferenceSetVolume(Volume);
  return ret;
}
/**
 * 设置本地摄像头开关
 * TODO
 */

ConferenceCtrl.ConferenceSetCameraButton=function(CallID,type) {
  console.log("会议摄像头"+type);
}

/**
 * 会议聚焦
 * @param   ConfID,        会议室ID   string
 * @param   ExtNum      成员分机号   string
 */

ConferenceCtrl.ConferenceFocus=function(ExtNum) {
  DispatchCtrlLib.ConferenceFocus(ExtNum)
}

/**
 * 退出会议
 * @param   ConfID,        会议室ID   int
 */

ConferenceCtrl.ConferenceQuit=function() {
  let ret = DispatchCtrlLib.ConferenceExit();
  return ret
}

/**
 * 结束会议
 * @param   ConfID,        会议室ID   string
 */

ConferenceCtrl.ConferenceClose=function() {
  let ret = DispatchCtrlLib.ConferenceEnd();
  return ret
}

/**
 * 移除会议成员
 * @param   ConfID,        会议室ID   string
 * @param   ExtNum,        成员分机号   string
 */

ConferenceCtrl.KickConferenceMem=function(ExtNum) {
  let ret = DispatchCtrlLib.ConferenceKick(ExtNum+"");
  return ret
}

/**
 * 禁言会议成员
 * @param   ConfID,        会议室ID   string
 * @param   ExtNum,        成员分机号   string
 * @param   Mute,          是否禁言 int 0-可讲话  1-禁言
 */

ConferenceCtrl.MuteConferenceMem=function(ExtNum,Mute) {
  let ret = DispatchCtrlLib.ConferenceMute(ExtNum, Mute);
  return ret
}

/**
 * 接受/拒绝会议邀请
 * @param   Handle	处理	Int	0-拒接会议邀请 1-接受会议邀请
 */

ConferenceCtrl.ConferenceHandleInvite=function(Handle) {
  let ret = DispatchCtrlLib.ConferenceHandleInvite(Handle);
  return ret
}

/**
 * 观看成员视频
 * @param   ExtNum	成员分机号   string
 * @param   VideoLib	成员视频显示的VideoLib	DispatchVideoLib	Null时表示结束视频观看
 */

ConferenceCtrl.ConferenceWatch=function(ExtNum, VideoLib) {
  let ret = DispatchCtrlLib.ConferenceWatch(ExtNum, VideoLib);
  return ret
}

/**
 * @param   通话中切换摄像头设备
 * @param
 DevID	视频源ID	String	none – 虚拟头像
 screen - 屏幕共享
 XXXXX- 摄像头ID    label
 */

ConferenceCtrl.ConferenceSetCamera =function(DevID){
  let ret = DispatchCtrlLib.ConferenceSetCamera(DevID);
  return ret;
}
/**
 * @param   通话中切换mic设备
 * @param    DevID	设备ID	String	XXXXX- 麦克风ID   label
 */

ConferenceCtrl.ConferenceSetMicphone=function(DevID){
  let ret = DispatchCtrlLib.ConferenceSetMicphone(DevID);
  // let ret ;
  // if(DevID=="screen"){
  //   ret = "screen";
  // }else{
  //   ret = "notshare";
  // }
  return ret;
}
/**
 * @param   通话中切换扬声器设备
 * @param    DevID    string     设备ID   label
 */

ConferenceCtrl.ConferenceSetSpeaker =function(DevID){
  let ret = DispatchCtrlLib.ConferenceSetSpeaker (DevID);
  return ret ;
}
/**
 * @param   切换主持人
 * @param    ExtNum   string     分机号
 */

ConferenceCtrl.ConferenceChangeHost =function(ExtNum){
  let ret = DispatchCtrlLib.ConferenceChangeHost (ExtNum);
  return ret ;
}

/**
 * 视频会议框加载
 */

ConferenceCtrl.ConferenceCanvasInit=function() {
  VideoLibConferenceArray[0] = new DispatchVideoLib();                     //加载远端div
  VideoLibConferenceArray[0].OnStatus = ConferenceCtrl.OnVideoStatus;
  VideoLibConferenceArray[0].Init(document.getElementById('conferenceVideo_div'));
  VideoLibConferenceArray[1] = new DispatchVideoLib();                     //加载本地div
  VideoLibConferenceArray[1].OnStatus = ConferenceCtrl.OnVideoStatus;
  VideoLibConferenceArray[1].Init(document.getElementById('conferenceVideoLocal_div'));
  return VideoLibConferenceArray;
}
/**
 * 视频会议本地框加载
 */
ConferenceCtrl.VideoLibConferenceLocalArray=function() {
  VideoLibConferenceLocalArray[0] = new DispatchVideoLib();                     //加载远端div
  VideoLibConferenceLocalArray[0].OnStatus = ConferenceCtrl.OnVideoStatus;
  VideoLibConferenceLocalArray[0].Init(document.getElementById('conferenceVideoLocal_div'));
  return VideoLibConferenceLocalArray;
}
/**
 * 视频会议框测试加载
 */

ConferenceCtrl.ConferenceCanvasInitTest=function() {
  for(let i=0;i<9;i++){
    VideoLibConferenceArray[i] = new DispatchVideoLib();                     //加载远端div
    VideoLibConferenceArray[i].OnStatus = ConferenceCtrl.OnVideoStatus;
    VideoLibConferenceArray[i].Init(document.getElementById('conferenceVideoDiv_'+i));
  }
    // VideoLibConferenceArray[0] = new DispatchVideoLib();                     //加载远端div
    // VideoLibConferenceArray[0].OnStatus = ConferenceCtrl.OnVideoStatus;
    // VideoLibConferenceArray[0].Init(document.getElementById('conferenceVideoDiv_0'));
    // VideoLibConferenceArray[1] = new DispatchVideoLib();                     //加载本地div
    // VideoLibConferenceArray[1].OnStatus = ConferenceCtrl.OnVideoStatus;
    // VideoLibConferenceArray[1].Init(document.getElementById('conferenceVideoDiv_1'));
    return VideoLibConferenceArray;
}
//
// ConferenceCtrl.startTestDisplay=function(channelId) {
//   VideoLibConferenceArray[0].StartDisplay(-1);
//   VideoLibConferenceArray[1].StartDisplay(channelId);
// }
//
// ConferenceCtrl.stopTestDisplay=function() {
//   VideoLibConferenceArray[0].StopDisplay();
//   // VideoLibConferenceArray[1].StopDisplay();
// }

ConferenceCtrl.OnVideoStatus=function(event) {
  console.log("OnVideoStatus" + event);
}
export { ConferenceCtrl }

